package com.cy.lib.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by CY on 2015/8/6.
 */
public class MapUtils {

    /**
     * 转成Url参数
     *
     * @param map
     * @return
     */
    public static String toUrlParams(Map<String, Object> map) {
        if (map != null && !map.isEmpty()) {
            StringBuffer sb = new StringBuffer();

            Set<Map.Entry<String, Object>> set = map.entrySet();
            Iterator<Map.Entry<String, Object>> iterator = set.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, Object> entry = iterator.next();
                sb.append(entry.getKey());
                sb.append("=");
                sb.append(entry.getValue());
                if (iterator.hasNext())
                    sb.append("&");
            }
            return sb.toString();
        }
        return null;
    }
}
